package com.mobile.challenge.ui.report.unit.admin.daily

import android.app.Application
import android.graphics.Color
import androidx.lifecycle.MutableLiveData
import com.github.mikephil.charting.data.BarData
import com.github.mikephil.charting.data.BarDataSet
import com.github.mikephil.charting.data.BarEntry
import com.mobile.challenge.ui.report.utils.IntegerFormat
import com.mobile.frame.mvvmframe.base.BaseModel
import com.mobile.frame.mvvmframe.base.DataViewModel
import javax.inject.Inject

class AdminUnitDailyReportViewModel @Inject constructor(application: Application, model: BaseModel?) : DataViewModel(application, model) {
    var barData = MutableLiveData<BarData>()

    fun generateData() {
        // y 数据
        val yValues: ArrayList<BarEntry> = ArrayList()
        // y2 数据
        val yValues2: ArrayList<BarEntry> = ArrayList()
        // y3 数据
        val yValues3: ArrayList<BarEntry> = ArrayList()
        // y4 数据
        val yValues4: ArrayList<BarEntry> = ArrayList()

        for (x in 0..3) {
            val y = (Math.random() * 30).toFloat() + 10
            yValues.add(BarEntry(x.toFloat(), y))
            val y2 = (Math.random() * 30).toFloat() + 10
            yValues2.add(BarEntry(x.toFloat(), y2))
            val y3 = (Math.random() * 30).toFloat() + 10
            yValues3.add(BarEntry(x.toFloat(), y3))
            val y4 = (Math.random() * 30).toFloat() + 10
            yValues4.add(BarEntry(x.toFloat(), y4))
        }

        yValues.add(BarEntry(4F, 0F))
        yValues2.add(BarEntry(4F, 0F))
        yValues3.add(BarEntry(4F, 0F))
        yValues4.add(BarEntry(4F, 0F))

        // y 轴数据集
        val barDataSet = BarDataSet(yValues, "NA")
        barDataSet.color = Color.parseColor("#f38181")

        // y2 轴数据集
        val barDataSet2 = BarDataSet(yValues2, "Office")
        barDataSet2.color = Color.parseColor("#fce38a")

        // y3 轴数据集
        val barDataSet3 = BarDataSet(yValues3, "Vacation")
        barDataSet3.color = Color.parseColor("#eaffd0")

        // y4 轴数据集
        val barDataSet4 = BarDataSet(yValues4, "WFH")
        barDataSet4.color = Color.parseColor("#95e1d3")

        val data = BarData(barDataSet, barDataSet2, barDataSet3, barDataSet4)

        val groupSpace = 0.2f
        val barSpace = 0.00f
        val barWidth = 0.2F
        // 设置 柱子宽度
        data.barWidth = barWidth
        data.groupBars(0.0f, groupSpace, barSpace)

        data.setValueFormatter(IntegerFormat())

        barData.value = data
    }


}